
package com.eyedog.video.NotifyDialog;

import com.eyedog.video.adv.AdvInstance;
import com.eyedog.video.entity.ADVEntity;
import com.eyedog.video.entity.NotifyEntity;
import com.eyedog.video.http.ICallback;

public class NotifyModel implements constract.INotifyModel {

    @Override
    public void loadNotify(final ICallback<NotifyEntity> callback) {
        if (AdvInstance.getInstance().hasAdvInited()) {
            ADVEntity advEntity = AdvInstance.getInstance().getNotifyAdv();
            if (advEntity != null) {
                NotifyEntity notifyEntity =
                    new NotifyEntity(0, advEntity.content, "官方", advEntity.url);
                callback.onLoadSuccess(notifyEntity);
            } else {
                callback.onLoadFailed("not any notify");
            }
        } else {
            AdvInstance.getInstance().initAdv(new ICallback<Boolean>() {
                @Override
                public void onLoadSuccess(Boolean aBoolean) {
                    ADVEntity advEntity = AdvInstance.getInstance().getNotifyAdv();
                    if (advEntity != null) {
                        NotifyEntity notifyEntity =
                            new NotifyEntity(0, advEntity.content, "官方", advEntity.url);
                        callback.onLoadSuccess(notifyEntity);
                    } else {
                        callback.onLoadFailed("not any notify");
                    }
                }

                @Override
                public void onLoadFailed(String err) {
                    callback.onLoadFailed("not any notify");
                }
            });
        }
    }
}
